package finalfinancialanalyst.gui;

import finalfinancialanalyst.business.Account;
import finalfinancialanalyst.business.AccountList;
import javax.swing.table.AbstractTableModel;

public class AccountModel extends AbstractTableModel { 
    
    private AccountList list;
    private String[] header = {
        "Account", "Currency", "Balance"
    };

    public AccountModel(AccountList list) {
        this.list = list;
    }

    public AccountList getList() {
        return list;
    }

    @Override
    public int getRowCount() {
        return list.size();
    }

    @Override
    public int getColumnCount() {
        return header.length;
    }

    @Override
    public String getColumnName(int columnIndex) {
        return header[columnIndex];
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
          return String.class;
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Account acc = list.get(rowIndex);
        switch (columnIndex) {
            case -1:
                return acc;            
            case 0:
                return acc.getName();
            case 1:
                return acc.getCurrency().getSymbol();
            case 2:
                return acc.getBalance().getAmount().toString();
            default:
                return null;

        }
    }
}
